import  javax.swing.*;
//import  javax.swing.event.*;
import java.awt.*;
//import java.awt.event.*;
//import java.beans.*;
import java.util.Random;
import java.util.concurrent.*;
import jahuwaldt.plot.*;
/**
 *
 * @author mith
 */

public class MainGUI extends JFrame {

	private static final long serialVersionUID = 1L;
	
//    /** Creates new form MainGUI */
//    public MainGUI(double [][]result, int line, int points) {
//        System.out.print("\n");
//        add(new PlotDraw(result, line, points));
//    }

    public MainGUI() {
        initComponents();
        SGAbox = true;
        resultSGA = null;
        isDataSGA = false;
        unfixed = "h";
        showed = "m";
    }

class Task implements Runnable {
    private double []x;
    private int nx;
    private double [][]y;
    private double []par;
//    private int npar;
    private double []X0;
    private int nX0;
    private boolean SGA;
    private int xshift;

    Task(double []_x, int _nx, double [][]_y, double []_par, double []_X0, int _nX0, boolean _SGA, int _xshift) {
        x = _x;
        nx = _nx;
        y = _y;
        par = _par;
        X0 = _X0;
        nX0 = _nX0;
        SGA = _SGA;
        xshift = _xshift;
    }

    public void run() {
        System.out.println("Taks: Start task");
        isDataSGA = false;
        int counter = 0;
        Gmros g = new Gmros();
        Random ran = new Random();

        int loop = 1;
        for(int i=0; i<=nx; i++) {
            jProgressBar.setValue(counter);
            par[xshift] = x[i];
            if(SGA == true) { y[counter] = g.jOnePointSGA(par, X0); }
            else { y[counter] = g.jOnePointGA(par, X0); }

            if(y[counter] == null) {
                for(int j=0; j<nX0; j++) {
                    X0[j] += ran.nextDouble()*X0[j]/100*loop*loop;
                }
                i--;
                // WARNING: this loop can be infinity!
                if(loop == 6) {
                    jProgressBar.setValue(0);
                    System.out.println("Taks: Error");
                    return;
                }
                loop++;
                continue;
            }

            if(i>=1) {
                for(int j=0; j<nX0; j++) { X0[j] = 2*y[i][j]-y[i-1][j]; }
            }
           else {
                for(int j=0; j<nX0; j++) { X0[j] = y[i][j]; }
            }

            counter++;
        }
        jProgressBar.setValue(counter);
        System.out.println("Taks: End task");
        isDataSGA = true;
    }
}
                         
    private void initComponents() {

        jLabelParameters = new JLabel();
        jButtonGenerate = new JButton();
        jTextField_h = new JTextField();
        jTextField_n = new JTextField();
        jTextField_t1 = new JTextField();
        jTextField_t2 = new JTextField();
        jTextField_b = new JTextField();
        jTextField_U = new JTextField();
        jProgressBar = new JProgressBar();
        jLabelFrom = new JLabel();
        jTextFieldFrom = new JTextField();
        jComboBoxUnfix = new JComboBox();
        jLabelUnfix = new JLabel();
        jLabelTo = new JLabel();
        jTextFieldTo = new JTextField();
        jLabelPoints = new JLabel();
        jTextFieldPoints = new JTextField();
        jSeparator1 = new JSeparator();
        jLabel_h = new JLabel();
        jLabel_n = new JLabel();
        jLabel_t1 = new JLabel();
        jLabel_t2 = new JLabel();
        jLabel_b = new JLabel();
        jLabel_U = new JLabel();
        jComboBoxShow = new JComboBox();
        jButtonShow = new JButton();
        jSeparator3 = new JSeparator();
        jLabelFeedback = new JLabel();
        jLabelX0 = new JLabel();
        jTextField_d = new JTextField();
        jLabel_d = new JLabel();
        jLabel_mu = new JLabel();
        jLabel_m = new JLabel();
        jLabel_ln = new JLabel();
        jLabel_lm = new JLabel();
        jTextField_mu = new JTextField();
        jTextField_m = new JTextField();
        jTextField_ln = new JTextField();
        jTextField_lm = new JTextField();
        jCheckBoxSGA = new JCheckBox();
        jMenuBar = new JMenuBar();
        jMenuFile = new JMenu();
        jMenuFileSaveAs = new JMenuItem();
        jMenuFileLoad = new JMenuItem();
        jMenuFileQuit = new JMenuItem();
        jMenuHelp = new JMenu();
        jMenuHelpHelp = new JMenuItem();
        jMenuHelpAbout = new JMenuItem();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("GA/SGA Solver");
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(461, 319));
        setResizable(false);

        jLabelParameters.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabelParameters.setText("Parameters:");

        jButtonGenerate.setText("Generate plot");
        jButtonGenerate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGenerateActionPerformed(evt);
            }
        });

        jTextField_h.setText("0.1");
        jTextField_n.setText("0.97");
        jTextField_t1.setText("1");
        jTextField_t2.setText("0.25");
        jTextField_b.setText("500");
        jTextField_U.setText("8");
        jLabelFrom.setText("from");
        jTextFieldFrom.setText("0");

        jComboBoxUnfix.setModel(new DefaultComboBoxModel(new String[] { "h", "n", "t1", "t2", "β", "U" }));
        jComboBoxUnfix.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxUnfixActionPerformed(evt);
            }
        });

        jLabelUnfix.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabelUnfix.setText("unfix");
        jLabelTo.setText("to");
        jTextFieldTo.setText("0.2");
        jLabelPoints.setText("points");
        jTextFieldPoints.setText("20");
        jLabel_h.setText("h");
        jLabel_n.setText("n");
        jLabel_t1.setText("t1");
        jLabel_t2.setText("t2");
        jLabel_b.setText("β");
        jLabel_U.setText("U");

        jComboBoxShow.setModel(new DefaultComboBoxModel(new String[] { "m", "d", "μ", "λ_n", "λ_m" }));
        jComboBoxShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxShowActionPerformed(evt);
            }
        });

        jButtonShow.setText("Show");
        jButtonShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonShowActionPerformed(evt);
            }
        });

        jLabelFeedback.setFont(new java.awt.Font("DejaVu Sans", 2, 10));
        jLabelFeedback.setHorizontalAlignment(SwingConstants.CENTER);
        jLabelFeedback.setText("Program ready...");

        jLabelX0.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabelX0.setText("Start point:");
        jTextField_d.setText("0.3");
        jLabel_d.setText("d");
        jLabel_mu.setText("μ");
        jLabel_m.setText("m");
        jLabel_ln.setText("λ_n");
        jLabel_lm.setText("λ_m");
        jTextField_mu.setText("3.5");
        jTextField_m.setText("0.2");
        jTextField_ln.setText("-3.6");
        jTextField_lm.setText("0.4");

        jCheckBoxSGA.setSelected(true);
        jCheckBoxSGA.setText("SGA activator");
        jCheckBoxSGA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxSGAActionPerformed(evt);
            }
        });

        jMenuFile.setText("File");

        jMenuFileSaveAs.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        jMenuFileSaveAs.setText("SaveAs");
        jMenuFile.add(jMenuFileSaveAs);

        jMenuFileLoad.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        jMenuFileLoad.setText("Load");
        jMenuFile.add(jMenuFileLoad);

        jMenuFileQuit.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        jMenuFileQuit.setText("Quit");
        jMenuFile.add(jMenuFileQuit);

        jMenuBar.add(jMenuFile);

        jMenuHelp.setText("Help");

        jMenuHelpHelp.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
        jMenuHelpHelp.setText("Help");
        jMenuHelp.add(jMenuHelpHelp);

        jMenuHelpAbout.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        jMenuHelpAbout.setText("About");
        jMenuHelp.add(jMenuHelpAbout);

        jMenuBar.add(jMenuHelp);

        setJMenuBar(jMenuBar);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jProgressBar, 0, 0, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonShow, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxShow, 0, 76, Short.MAX_VALUE))
                            .addComponent(jButtonGenerate, GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabelUnfix)
                                    .addComponent(jLabelTo)
                                    .addComponent(jLabelFrom)
                                    .addComponent(jLabelPoints))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldPoints)
                                    .addComponent(jTextFieldTo)
                                    .addComponent(jTextFieldFrom)
                                    .addComponent(jComboBoxUnfix, GroupLayout.PREFERRED_SIZE, 98, GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 155, Short.MAX_VALUE))
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelParameters)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel_U)
                                            .addComponent(jLabel_t2)
                                            .addComponent(jLabel_b))
                                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel_t1)
                                            .addComponent(jLabel_n)))
                                    .addComponent(jLabel_h))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextField_h)
                                    .addComponent(jTextField_U)
                                    .addComponent(jTextField_b)
                                    .addComponent(jTextField_t2)
                                    .addComponent(jTextField_t1)
                                    .addComponent(jTextField_n, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE))))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxSGA)
                            .addComponent(jLabelX0)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel_ln)
                                    .addComponent(jLabel_m)
                                    .addComponent(jLabel_mu)
                                    .addComponent(jLabel_d)
                                    .addComponent(jLabel_lm))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextField_lm, GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(jTextField_d, GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(jTextField_mu, GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(jTextField_m, GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(jTextField_ln, GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)))))
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSeparator3, GroupLayout.PREFERRED_SIZE, 437, GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabelFeedback, GroupLayout.PREFERRED_SIZE, 437, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelUnfix)
                    .addComponent(jComboBoxUnfix, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelParameters)
                    .addComponent(jLabelX0))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_h, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_h))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_n, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_n))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_t1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_t1))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_t2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_t2))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_b, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_b))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_U, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_U)
                            .addComponent(jCheckBoxSGA)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_d, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_d))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_mu, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_mu))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField_m, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel_m))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_ln)
                            .addComponent(jTextField_ln, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel_lm)
                            .addComponent(jTextField_lm, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldFrom, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelFrom))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldTo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelTo))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelPoints)
                            .addComponent(jTextFieldPoints, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonGenerate)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jProgressBar, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxShow, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonShow))))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelFeedback)
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }                      
        
    private void jComboBoxShowActionPerformed(java.awt.event.ActionEvent evt) {                                              
        showed = (String)(((JComboBox)evt.getSource()).getSelectedItem());
    }                                             

    private void jButtonGenerateActionPerformed(java.awt.event.ActionEvent evt) {                                                
        isDataSGA = false;
        boolean SGA = SGAbox;
        int N = 3; if(SGA) { N = 5; }
        double from = Double.parseDouble(jTextFieldFrom.getText());
        double to = Double.parseDouble(jTextFieldTo.getText());
        points = Integer.parseInt(jTextFieldPoints.getText());
        double []par = new double[6]; // h, n, t1, t2, beta, U
            par[0] = Double.parseDouble(jTextField_h.getText());
            par[1] = Double.parseDouble(jTextField_n.getText());
            par[2] = Double.parseDouble(jTextField_t1.getText());
            par[3] = Double.parseDouble(jTextField_t2.getText());
            par[4] = Double.parseDouble(jTextField_b.getText());
            par[5] = Double.parseDouble(jTextField_U.getText());
        double []X0 = new double[N]; // mu, m, d, ln, lm
            X0[0] = Double.parseDouble(jTextField_mu.getText());
            X0[1] = Double.parseDouble(jTextField_m.getText());
            X0[2] = Double.parseDouble(jTextField_d.getText());
        if(SGA == true) {
            X0[3] = Double.parseDouble(jTextField_ln.getText());
            X0[4] = Double.parseDouble(jTextField_lm.getText());
        }
        resultSGA = new double[points+1][];
        for(int i=0; i<=points; i++) { resultSGA[i] = null; }

        // DEBUG
        System.out.println("SGA = " + SGA);
        System.out.println("from = " + from);
        System.out.println("to = " + to);
        System.out.println("points = " + points);
        // END DEBUG

        int counter = 0;
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        jProgressBar.setMaximum(points);
        jProgressBar.setMinimum(0);
        jProgressBar.setStringPainted(false);
        jProgressBar.setValue(counter);

        int xshift = 0;
        if(unfixed.equals("h") == true) { xshift = 0; }
        else if(unfixed.equals("n") == true) { xshift = 1; }
        else if(unfixed.equals("t1") == true) { xshift = 2; }
        else if(unfixed.equals("t2") == true) { xshift = 3; }
        else if(unfixed.equals("β") == true) { xshift = 4; }
        else if(unfixed.equals("U") == true) { xshift = 5; }
        else { System.out.println("BLAD 342"); }

        x = new double[points+1];
        double step = (to-from)/((double)points);
        for(int i=0; i<=points; i++) {
            x[i] = from + i*step;
        }

        // For SGA
        System.out.println("Start task");
        Task task = new Task(x, points, resultSGA, par, X0, N, SGA, xshift);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.execute(task);
        System.out.println("End task");

        setCursor(null);
    }                                               

    private void jCheckBoxSGAActionPerformed(java.awt.event.ActionEvent evt) {                                             
        SGAbox = !SGAbox;
        if(SGAbox == false) {
            jTextField_mu.setText("-0.4");
            jTextField_m.setText("0.05");
            jTextField_d.setText("0.3");
            jTextField_ln.setText("none");
            jTextField_lm.setText("none");
        }
        else {
            jTextField_mu.setText("3.5");
            jTextField_m.setText("0.2");
            jTextField_d.setText("0.3");
            jTextField_ln.setText("-3.6");
            jTextField_lm.setText("0.4");
        }
    }                                            

    private void jButtonShowActionPerformed(java.awt.event.ActionEvent evt) {                                            
        if(resultSGA == null || isDataSGA == false) return;
        System.out.println("DEBUG: Show button");

        int shiftShowed = 0;
        if(showed.equals("m") == true) { shiftShowed = 1; }
        else if(showed.equals("d") == true) { shiftShowed = 2; }
        else if(showed.equals("μ") == true) { shiftShowed = 0; }
        else if(showed.equals("λ_n") == true && SGAbox) { shiftShowed = 3; }
        else if(showed.equals("λ_m") == true && SGAbox) { shiftShowed = 4; }
        else { System.out.println("BLAD 372"); }

        double []y = new double[points+1];
        for(int i=0; i<=points; i++) {
            y[i] = resultSGA[i][shiftShowed];
        }

        String title;
        if(SGAbox) { title = "SGA method"; } else { title = "GA method"; }


        Plot2D aPlot = new SimplePlotXY(x, y, title, unfixed, showed, null, null, new CircleSymbol());
        PlotPanel panel = new PlotPanel(aPlot);
        panel.setBackground( Color.white );
        
      PlotWindow window = new PlotWindow("SimplePlotXY Plot Window", panel);
      window.setSize(700, 400);
      window.setLocation(470,0);
      window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      window.show();
    }                                           

    private void jComboBoxUnfixActionPerformed(java.awt.event.ActionEvent evt) {                                               
        unfixed = (String)(((JComboBox)evt.getSource()).getSelectedItem());
        //System.out.println(unfixed);
    }                                              


    void jMenuDebug() {
       System.out.println("jMenuFileSaveAs start");
    }

//    public void actionPerformed(ActionEvent e) {
//        JMenuItem source = (JMenuItem)(e.getSource());
//        String s = "Action event detected."
//                   + "    Event source: " + source.getText()
//                   + " (an instance of " + getClassName(source) + ")";
//        output.append(s + newline);
//        output.setCaretPosition(output.getDocument().getLength());
//    }

//    jMenuFileSaveAs.addItemListener(
//        new ItemListener() {
//            public void itemStateChanged(ItemEvent e) {
//                System.out.println("jMenuFileSaveAs start");
//            }
//        }
//    );
//    jMenuFileSaveAs.addActionListener(
//        new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//                System.out.println("jMenuFileSaveAs start");
//            }
//        }
//    );
//
//    private void jMenuFileSaveAsActionPerformed(java.awt.event.ActionEvent evt) {
//        System.out.println("jMenuFileSaveAsActionPerformed start");
//    }
//
//    private void jMenuFileLoadActionPerformed(java.awt.event.ActionEvent evt) {
//        System.out.println("jMenuFileLoadActionPerformed start");
//    }

    // Variables declaration                   
    private JButton jButtonGenerate;
    private JButton jButtonShow;
    private JCheckBox jCheckBoxSGA;
    private JComboBox jComboBoxShow;
    private JComboBox jComboBoxUnfix;
    private JLabel jLabelFeedback;
    private JLabel jLabelFrom;
    private JLabel jLabelParameters;
    private JLabel jLabelPoints;
    private JLabel jLabelTo;
    private JLabel jLabelUnfix;
    private JLabel jLabelX0;
    private JLabel jLabel_U;
    private JLabel jLabel_b;
    private JLabel jLabel_d;
    private JLabel jLabel_h;
    private JLabel jLabel_lm;
    private JLabel jLabel_ln;
    private JLabel jLabel_m;
    private JLabel jLabel_mu;
    private JLabel jLabel_n;
    private JLabel jLabel_t1;
    private JLabel jLabel_t2;
    private JMenuBar jMenuBar;
    private JMenu jMenuFile;
    private JMenuItem jMenuFileLoad;
    private JMenuItem jMenuFileQuit;
    private JMenuItem jMenuFileSaveAs;
    private JMenu jMenuHelp;
    private JMenuItem jMenuHelpAbout;
    private JMenuItem jMenuHelpHelp;
    private JProgressBar jProgressBar;
    private JSeparator jSeparator1;
    private JSeparator jSeparator3;
    private JTextField jTextFieldFrom;
    private JTextField jTextFieldPoints;
    private JTextField jTextFieldTo;
    private JTextField jTextField_U;
    private JTextField jTextField_b;
    private JTextField jTextField_d;
    private JTextField jTextField_h;
    private JTextField jTextField_lm;
    private JTextField jTextField_ln;
    private JTextField jTextField_m;
    private JTextField jTextField_mu;
    private JTextField jTextField_n;
    private JTextField jTextField_t1;
    private JTextField jTextField_t2;               
    private double[][] resultSGA;
//    private double[][] resultGA;
    private double []x;
    private int points;
    private boolean SGAbox;
    private boolean isDataSGA;
    private String unfixed;
    private String showed;
}
